<?php
/**
 *  
 * @package package_name
 * @author Mervin.Wong<mervin0502@163.com>
 * @Copyright
 * @license  http://www.apache.org/licenses/LICENSE-2.0
 * @version 0.1.0
 * @date 2013-2-24下午9:08:55
 *
 */

/**
 * 
 * @author Mervin
 *
 */
 class Index_model extends CI_Model{
 	/**
 	 * 构造函数
 	 */
 	public function __construct(){
 		parent::__construct();
 		$this->load->database();
 	}
 	
 	/**
 	 * 登录检测
 	 * @param string $name
 	 * @param string $password
 	 * @return string|array 成功，返回用户信息数组
 	 */
 	public function login($name, $password, $session_id){
 		$msg = '';
 		$this->db->select('*');
 		$this->db->from('user');
 		$this->db->where('name', $name);
 		$query = $this->db->get();
 		if ($query->num_rows > 0){
 			$row = $query->row_array();
 			if($row['password'] == $password){
 				$this->db->set('status', 'yes');
 				$this->db->where('session_id', $session_id);
 				$this->db->update('sessions');
 				$msg = $row;
 			}else{
 				$msg = '密码错误';
 			}
 		}else{
 			$msg ='用户名不存在！';
 		}
 		return $msg;
 	}
 	
 	public function logout($session_id){
 		$this->db->set('status', 'no');
 		$this->db->where('session_id', $session_id);
 		$this->db->update('sessions');
 		if($this->db->affected_rows() > 0){
 			return true;
 		}else{
 			return false;
 		}
 	}
 	

 }


/* End of file index_model.php */
/* Location : ./apps/admin/models/index_model.php */